package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

/* compiled from: Player.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawCraftsMenu.class */
public class DrawCraftsMenu extends Menu {
    public static int lastCurrIndex = 0;
    public static int lastCursorPos = 0;
    Sprite arrow;
    Sprite arrowWhite;
    Sprite textBox;
    public Action.Layer layer;
    Map<Integer, Vector2> arrowCoords;
    Vector2 newPos;
    Sprite helperSprite;
    ArrayList<ArrayList<Sprite>> spritesToDraw;
    int cursorDelay;
    int cursorPos;
    int currIndex;
    ArrayList<String> craftsList;
    Sprite downArrow;
    int downArrowTimer;
    Sprite craftReqsTextbox;
    Sprite titleTextbox;
    String currCraft;
    ArrayList<String> craftReqs;
    ArrayList<Color> craftReqColors;
    Vector2 topLeft;
    boolean refresh;
    ArrayList<Player.Craft> crafts;
    Color prevColor;

    public DrawCraftsMenu(Game game, Action nextAction) {
        this(game, Player.crafts, (Menu) null);
        this.nextAction = nextAction;
    }

    public DrawCraftsMenu(Game game, ArrayList<Player.Craft> crafts, Action nextAction) {
        this(game, crafts, (Menu) null);
        this.nextAction = nextAction;
    }

    public DrawCraftsMenu(Game game, Menu prevMenu) {
        this(game, Player.crafts, prevMenu);
    }

    public DrawCraftsMenu(Game game, ArrayList<Player.Craft> crafts, Menu prevMenu) {
        this.layer = Action.Layer.gui_106;
        this.arrowCoords = new HashMap();
        this.spritesToDraw = new ArrayList<>();
        this.currCraft = "";
        this.craftReqs = new ArrayList<>();
        this.craftReqColors = new ArrayList<>();
        this.topLeft = new Vector2(0.0f, 26.0f);
        this.refresh = false;
        this.prevColor = new Color();
        this.crafts = crafts;
        this.prevMenu = prevMenu;
        this.disabled = false;
        this.cursorDelay = 0;
        this.arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
        this.arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
        this.textBox = new Sprite(TextureCache.get(Gdx.files.internal("menu/item_menu1.png")), 0, 0, 160, 144);
        this.craftReqsTextbox = new Sprite(TextureCache.get(Gdx.files.internal("textbox_bg1.png")), 0, 0, 160, 144);
        this.titleTextbox = new Sprite(TextureCache.get(Gdx.files.internal("title_bg1.png")), 0, 0, 160, 144);
        this.downArrow = new Sprite(TextureCache.get(Gdx.files.internal("arrow_down.png")), 0, 0, 7, 5);
        this.downArrow.setPosition(144.0f, 50.0f);
        this.downArrowTimer = 0;
        this.currIndex = lastCurrIndex;
        this.cursorPos = lastCursorPos;
        this.arrowCoords.put(0, new Vector2(41.0f, 104.0f));
        this.arrowCoords.put(1, new Vector2(41.0f, 88.0f));
        this.arrowCoords.put(2, new Vector2(41.0f, 72.0f));
        this.arrowCoords.put(3, new Vector2(41.0f, 56.0f));
        this.newPos = this.arrowCoords.get(Integer.valueOf(this.cursorPos));
        this.arrow.setPosition(this.newPos.x, this.newPos.y);
        this.craftsList = new ArrayList<>();
        Iterator<Player.Craft> it = this.crafts.iterator();
        while (it.hasNext()) {
            this.craftsList.add(it.next().name);
        }
        this.craftsList.add("Cancel");
        if (this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts) {
            this.textBox.setPosition(0.0f, 16.0f);
            this.craftReqsTextbox = new Sprite(TextureCache.get(Gdx.files.internal("textbox_bg2.png")), 0, 0, 160, 144);
            this.downArrow.setPosition(144.0f, 66.0f);
        }
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    public void refresh(Game game, int index) {
        this.craftReqs.clear();
        this.craftReqColors.clear();
        Iterator<Player.Craft> it = this.crafts.get(index).requirements.iterator();
        while (it.hasNext()) {
            Player.Craft craft = it.next();
            String text = craft.name.toUpperCase(Locale.ROOT);
            int numNeeded = craft.amount;
            int offset = 0;
            if (numNeeded >= 100) {
                offset = 2;
            } else if (numNeeded >= 10) {
                offset = 1;
            }
            for (int i = 0; i < (16 - craft.name.length()) - offset; i++) {
                text = text + " ";
            }
            String text2 = (text + "x") + String.valueOf(numNeeded);
            if (!game.player.hasItem(craft.name) || game.player.getItemAmount(craft.name).intValue() < numNeeded) {
                this.craftReqColors.add(new Color(1.0f, 1.0f, 1.0f, 0.5f));
            } else {
                this.craftReqColors.add(new Color(1.0f, 1.0f, 1.0f, 1.0f));
            }
            this.craftReqs.add(text2);
        }
        this.spritesToDraw.clear();
        Iterator<String> it2 = this.craftsList.iterator();
        while (it2.hasNext()) {
            String entry = it2.next();
            char[] textArray = entry.toUpperCase(Locale.ROOT).toCharArray();
            int i2 = 0;
            ArrayList<Sprite> word = new ArrayList<>();
            for (char letter : textArray) {
                Sprite letterSprite = game.textDict.get(Character.valueOf(letter));
                if (letterSprite == null) {
                    letterSprite = game.textDict.get(null);
                }
                if (this.crafts == game.player.regiCrafts) {
                    letterSprite = game.brailleDict.get(Character.valueOf(letter));
                    if (letterSprite == null) {
                        letterSprite = game.textDict.get(' ');
                    }
                }
                Sprite currSprite = new Sprite(letterSprite);
                currSprite.setPosition((float) (48 + (8 * i2)), 104.0f);
                word.add(currSprite);
                i2++;
            }
            if (game.player.hasItem(entry)) {
                char[] numItemsArray = String.format(Locale.ROOT, "%02d", game.player.getItemAmount(entry)).toCharArray();
                int i3 = 10;
                boolean foundDigit = false;
                for (char letter2 : numItemsArray) {
                    i3++;
                    if (letter2 != '0' || foundDigit) {
                        foundDigit = true;
                        Sprite currSprite2 = new Sprite(game.textDict.get(Character.valueOf(letter2)));
                        currSprite2.setPosition((float) (48 + (8 * i3)), 104.0f);
                        word.add(currSprite2);
                    }
                }
            }
            this.spritesToDraw.add(word);
        }
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        while (this.currIndex + this.cursorPos > this.crafts.size() - 2) {
            if (this.currIndex <= 0) {
                if (this.cursorPos <= 0) {
                    break;
                }
                this.cursorPos--;
            } else {
                this.currIndex--;
            }
        }
        lastCurrIndex = this.currIndex;
        lastCursorPos = this.cursorPos;
        this.newPos = this.arrowCoords.get(Integer.valueOf(this.cursorPos));
        this.arrow.setPosition(this.newPos.x, this.newPos.y);
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.prevMenu != null) {
            this.prevMenu.step(game);
        }
        if (!(this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts)) {
            game.uiBatch.draw(this.titleTextbox, this.titleTextbox.getX(), this.titleTextbox.getY());
        }
        game.uiBatch.draw(this.craftReqsTextbox, this.craftReqsTextbox.getX(), this.craftReqsTextbox.getY());
        game.uiBatch.draw(this.textBox, this.textBox.getX(), this.textBox.getY());
        int j = 0;
        for (int i = 0; i < this.spritesToDraw.size(); i++) {
            if (i >= this.currIndex && i < this.currIndex + 4) {
                Iterator<Sprite> it = this.spritesToDraw.get(i).iterator();
                while (it.hasNext()) {
                    Sprite sprite = it.next();
                    int extra = 0;
                    if (this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts) {
                        extra = 16;
                    }
                    game.uiBatch.draw(sprite, sprite.getX(), (sprite.getY() - ((float) (j * 16))) + ((float) extra));
                }
                j++;
            }
        }
        int index = lastCurrIndex + lastCursorPos;
        if (index >= this.crafts.size()) {
            this.craftReqs.clear();
            this.craftReqColors.clear();
            this.currCraft = "";
        } else {
            String curr = this.crafts.get(index).name;
            if (curr != null && !this.currCraft.equals(curr)) {
                this.currCraft = curr;
                refresh(game, index);
            }
        }
        char[] textArray = "CRAFTING MENU".toCharArray();
        if (this.crafts == game.player.fossilCrafts) {
            textArray = "FOSSIL MENU".toCharArray();
        }
        int j2 = 0;
        for (char letter : textArray) {
            Sprite letterSprite = game.textDict.get(Character.valueOf(letter));
            if (letterSprite == null) {
                letterSprite = game.textDict.get(null);
            }
            if (this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts) {
                break;
            }
            game.uiBatch.draw(letterSprite, (float) (8 + (8 * j2)), 128.0f);
            j2++;
        }
        for (int i2 = 0; i2 < this.craftReqs.size(); i2++) {
            String word = this.craftReqs.get(i2);
            for (int k = 0; k < word.length(); k++) {
                char letter2 = word.charAt(k);
                int extra2 = 0;
                if (this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts) {
                    extra2 = 16;
                }
                Sprite letterSprite2 = new Sprite((Sprite) game.textDict.get(Character.valueOf(letter2)));
                letterSprite2.setPosition(this.topLeft.x + 8.0f + ((float) (8 * k)), (this.topLeft.y - ((float) (16 * i2))) + ((float) extra2));
                this.prevColor.set(game.uiBatch.getColor());
                game.uiBatch.setColor(this.prevColor.r, this.prevColor.g, this.prevColor.b, this.craftReqColors.get(i2).a);
                game.uiBatch.draw(letterSprite2, letterSprite2.getX(), letterSprite2.getY());
                game.uiBatch.setColor(this.prevColor);
            }
        }
        if (this.disabled) {
            int extra3 = 0;
            if (this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts) {
                extra3 = 16;
            }
            this.arrowWhite.setPosition(this.newPos.x, this.newPos.y + ((float) extra3));
            game.uiBatch.draw(this.arrowWhite, this.arrowWhite.getX(), this.arrowWhite.getY());
            return;
        }
        if (this.refresh) {
            refresh(game, index);
            this.refresh = false;
        }
        if (InputProcessor.upJustPressed) {
            if (this.cursorPos > 0) {
                this.cursorPos--;
                this.newPos = this.arrowCoords.get(Integer.valueOf(this.cursorPos));
            } else if (this.currIndex > 0) {
                this.currIndex--;
            }
            lastCurrIndex = this.currIndex;
            lastCursorPos = this.cursorPos;
        } else if (InputProcessor.downJustPressed) {
            if (this.cursorPos < 2 && this.cursorPos + 1 < this.craftsList.size()) {
                this.cursorPos++;
                this.newPos = this.arrowCoords.get(Integer.valueOf(this.cursorPos));
            } else if (this.currIndex < this.craftsList.size() - 3) {
                this.currIndex++;
            }
            lastCurrIndex = this.currIndex;
            lastCursorPos = this.cursorPos;
        }
        if (this.cursorDelay >= 5) {
            int extra4 = 0;
            if (this.crafts == game.player.regiCrafts || this.crafts == Player.kilnCrafts) {
                extra4 = 16;
            }
            this.arrow.setPosition(this.newPos.x, this.newPos.y + ((float) extra4));
            game.uiBatch.draw(this.arrow, this.arrow.getX(), this.arrow.getY());
        } else {
            this.cursorDelay++;
        }
        if (this.craftsList.size() - this.currIndex > 4) {
            if (this.downArrowTimer < 22) {
                game.uiBatch.draw(this.downArrow, this.downArrow.getX(), this.downArrow.getY());
            }
            this.downArrowTimer++;
        } else {
            this.downArrowTimer = 0;
        }
        if (this.downArrowTimer > 41) {
            this.downArrowTimer = 0;
        }
        if (InputProcessor.aJustPressed) {
            game.actionStack.remove(this);
            game.insertAction(new PlayMusic("click1", (Action) null));
            if ("Cancel".equals(this.craftsList.get(this.currIndex + this.cursorPos))) {
                lastCurrIndex = this.currIndex;
                lastCursorPos = this.cursorPos;
                if (this.prevMenu != null) {
                    this.prevMenu.disabled = false;
                }
                game.insertAction(new WaitFrames(game, 3, this.prevMenu));
                game.insertAction(new WaitFrames(game, 3, this.nextAction));
                return;
            }
            this.refresh = true;
            this.disabled = true;
            if (this.crafts == game.player.regiCrafts || this.crafts == game.player.fossilCrafts) {
                SelectAmount.amount = 1;
                game.insertAction(new Selected(this.crafts, this));
                return;
            }
            game.insertAction(new SelectAmount(this.crafts, this));
        } else if (InputProcessor.bJustPressed) {
            lastCurrIndex = this.currIndex;
            lastCursorPos = this.cursorPos;
            if (this.prevMenu != null) {
                this.prevMenu.disabled = false;
            }
            game.actionStack.remove(this);
            game.insertAction(this.prevMenu);
            game.insertAction(this.nextAction);
            game.insertAction(new PlayMusic("click1", (Action) null));
        }
    }

    /* compiled from: Player.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/DrawCraftsMenu$Intro.class */
    public static class Intro extends Action {
        int length;
        public Action.Layer layer = Action.Layer.gui_110;
        Menu prevMenu;

        public Intro(Menu prevMenu, int length, Action nextAction) {
            super(new Object[0]);
            this.prevMenu = prevMenu;
            this.nextAction = nextAction;
            this.length = length;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.prevMenu != null) {
                this.prevMenu.step(game);
            }
            this.length--;
            if (this.length <= 0) {
                game.insertAction(this.nextAction);
                game.actionStack.remove(this);
            }
        }
    }

    /* compiled from: Player.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/DrawCraftsMenu$SelectAmount.class */
    static class SelectAmount extends Menu {
        public static int amount = 0;
        ArrayList<Player.Craft> crafts;
        public Action.Layer layer = Action.Layer.gui_105;
        int maxAmount = 1;
        Sprite textbox = new Sprite(TextureCache.get(Gdx.files.internal("amount_bg1.png")), 0, 0, 160, 144);

        public SelectAmount(ArrayList<Player.Craft> crafts, Menu prevMenu) {
            this.crafts = crafts;
            this.prevMenu = prevMenu;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            amount = 1;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.prevMenu != null) {
                this.prevMenu.step(game);
            }
            this.textbox.draw(game.uiBatch);
            if (!this.disabled) {
                if (InputProcessor.upJustPressed) {
                    if (game.player.hasCraftRequirements(this.crafts, DrawCraftsMenu.lastCurrIndex + DrawCraftsMenu.lastCursorPos, amount + 1)) {
                        amount++;
                    }
                } else if (InputProcessor.downJustPressed) {
                    if (amount > 1) {
                        amount--;
                    }
                } else if (InputProcessor.rightJustPressed) {
                    int index = DrawCraftsMenu.lastCurrIndex + DrawCraftsMenu.lastCursorPos;
                    for (int i = 0; i < 10; i++) {
                        if (game.player.hasCraftRequirements(this.crafts, index, amount + 1)) {
                            amount++;
                        }
                    }
                    if (amount >= 99) {
                        amount = 99;
                    }
                } else if (InputProcessor.leftJustPressed) {
                    amount -= 10;
                    if (amount <= 1) {
                        amount = 1;
                    }
                }
                String word = "x" + String.format(Locale.ROOT, "%02d", Integer.valueOf(amount));
                for (int i2 = 0; i2 < word.length(); i2++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(word.charAt(i2))), (float) (130 + (8 * i2)), 56.0f);
                }
                if (InputProcessor.aJustPressed) {
                    this.disabled = true;
                    game.actionStack.remove(this);
                    game.insertAction(new Selected(this.crafts, this));
                } else if (InputProcessor.bJustPressed) {
                    game.insertAction(new PlayMusic("click1", (Action) null));
                    game.actionStack.remove(this);
                    this.prevMenu.disabled = false;
                    game.insertAction(this.prevMenu);
                }
            }
        }
    }

    /* compiled from: Player.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/DrawCraftsMenu$Selected.class */
    static class Selected extends Menu {
        Sprite arrow;
        Sprite arrowWhite;
        Sprite textBoxTop;
        Sprite textBoxMiddle;
        Sprite textBoxBottom;
        int curr;
        Vector2 newPos;
        Sprite helperSprite;
        ArrayList<Player.Craft> crafts;
        public Action.Layer layer = Action.Layer.gui_105;
        int textboxDelay = 0;
        Map<Integer, Vector2> getCoords = new HashMap();
        ArrayList<String> words = new ArrayList<>();

        public Selected(ArrayList<Player.Craft> crafts, Menu prevMenu) {
            this.crafts = crafts;
            this.prevMenu = prevMenu;
            if (crafts == Game.staticGame.player.fossilCrafts) {
                this.words.add("CREATE");
            } else {
                this.words.add("CRAFT");
            }
            this.words.add("CANCEL");
            this.getCoords.put(0, new Vector2(97.0f, 56.0f));
            this.getCoords.put(1, new Vector2(97.0f, 40.0f));
            this.arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
            this.arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
            this.textBoxTop = new Sprite(TextureCache.get(Gdx.files.internal("menu/selected_menu_top.png")), 0, 0, 71, 19);
            this.textBoxMiddle = new Sprite(TextureCache.get(Gdx.files.internal("menu/selected_menu_middle.png")), 0, 0, 71, 16);
            this.textBoxBottom = new Sprite(TextureCache.get(Gdx.files.internal("menu/selected_menu_bottom.png")), 0, 0, 71, 19);
            this.newPos = this.getCoords.get(0);
            this.arrow.setPosition(this.newPos.x, this.newPos.y);
            this.curr = 0;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.prevMenu != null) {
                this.prevMenu.step(game);
            }
            if (this.textboxDelay < 1) {
                this.textboxDelay++;
                return;
            }
            for (int i = 0; i < this.words.size(); i++) {
                if (i == 0) {
                    game.uiBatch.draw(this.textBoxTop, 89.0f, (float) (68 + (16 * (this.words.size() - 3))));
                } else if (i == this.words.size() - 1) {
                    game.uiBatch.draw(this.textBoxBottom, 89.0f, 33.0f);
                } else {
                    game.uiBatch.draw(this.textBoxMiddle, 89.0f, (float) (52 + (16 * ((this.words.size() - i) - 2))));
                }
                String word = this.words.get(i);
                for (int j = 0; j < word.length(); j++) {
                    game.uiBatch.draw(game.textDict.get(Character.valueOf(word.charAt(j))), (float) (104 + (8 * j)), (float) (72 - (16 * ((i - this.words.size()) + 3))));
                }
            }
            this.arrowWhite.setPosition(this.newPos.x, this.newPos.y);
            this.arrowWhite.draw(game.uiBatch);
            if (!this.disabled) {
                this.arrow.setPosition(this.newPos.x, this.newPos.y);
                game.uiBatch.draw(this.arrow, this.arrow.getX(), this.arrow.getY());
                if (InputProcessor.upJustPressed) {
                    if (this.curr > 0) {
                        this.curr--;
                        this.newPos = this.getCoords.get(Integer.valueOf(this.curr));
                    }
                } else if (InputProcessor.downJustPressed && this.curr < this.words.size() - 1) {
                    this.curr++;
                    this.newPos = this.getCoords.get(Integer.valueOf(this.curr));
                }
                if (InputProcessor.aJustPressed) {
                    String word2 = this.words.get(this.curr);
                    if ("CANCEL".equals(word2)) {
                        game.insertAction(new PlayMusic("click1", (Action) null));
                        game.actionStack.remove(this);
                        this.prevMenu.disabled = false;
                        game.insertAction(this.prevMenu);
                    } else if ("CRAFT".equals(word2) || "CREATE".equals(word2)) {
                        int index = DrawCraftsMenu.lastCurrIndex + DrawCraftsMenu.lastCursorPos;
                        if (game.type == Game.Type.CLIENT) {
                            game.client.sendTCP(new Network.Craft(game.player.network.id, index, SelectAmount.amount));
                        }
                        if (!game.player.hasCraftRequirements(this.crafts, index, SelectAmount.amount)) {
                            this.disabled = true;
                            game.insertAction(new PlayMusic("error1", new SetField(this, "disabled", false, null)));
                        } else if (this.crafts == game.player.regiCrafts) {
                            Iterator<Player.Craft> it = this.crafts.get(index).requirements.iterator();
                            while (it.hasNext()) {
                                Player.Craft req = it.next();
                                int newAmt = game.player.getItemAmount(req.name).intValue() - (req.amount * SelectAmount.amount);
                                game.player.setItemAmount(req.name, newAmt);
                                if (newAmt <= 0) {
                                    game.player.removeItem(req.name);
                                }
                            }
                            Player.Craft regiCraft = this.crafts.remove(index);
                            game.actionStack.remove(this);
                            game.actionStack.remove(this.prevMenu);
                            String dirFacing = game.player.dirFacing;
                            game.player.dirFacing = "up";
                            Player player = game.player;
                            Objects.requireNonNull(player);
                            game.insertAction(new WaitFrames(game, 20, new Player.Emote("!", new WaitFrames(game, 30, new SetField(game.player, "currSprite", game.player.standingSprites.get(game.player.dirFacing), new RegigigasIntroAnim(regiCraft.name, dirFacing, null))))));
                        } else if (this.crafts == game.player.fossilCrafts) {
                            Iterator<Player.Craft> it2 = this.crafts.get(index).requirements.iterator();
                            while (it2.hasNext()) {
                                Player.Craft req2 = it2.next();
                                int newAmt2 = game.player.getItemAmount(req2.name).intValue() - (req2.amount * SelectAmount.amount);
                                game.player.setItemAmount(req2.name, newAmt2);
                                if (newAmt2 <= 0) {
                                    game.player.removeItem(req2.name);
                                }
                            }
                            Player.Craft fossilCraft = this.crafts.get(index);
                            game.actionStack.remove(this);
                            game.actionStack.remove(this.prevMenu);
                            game.player.dirFacing = "right";
                            Player player2 = game.player;
                            Objects.requireNonNull(player2);
                            Action newAction = new WaitFrames(game, 20, new Player.Emote("!", new WaitFrames(game, 30, new SetField(game.player, "currSprite", game.player.standingSprites.get(game.player.dirFacing), null))));
                            if (game.player.hmPokemon != null) {
                                newAction.append(new SetField(game.player.hmPokemon, "dirFacing", "right", null));
                            }
                            game.insertAction(new WaitFrames(game, 20, new PlayMusic("computer1", 0.5f, false, null)));
                            game.insertAction(new FossilMachinePowerUp.DoRevive(fossilCraft.name, null));
                            game.insertAction(newAction);
                        } else {
                            game.player.craftItem(this.crafts, index, SelectAmount.amount);
                            game.actionStack.remove(this);
                            game.insertAction(this.prevMenu.prevMenu);
                            String plural = "";
                            if (SelectAmount.amount > 1 && !this.crafts.get(index).name.toLowerCase(Locale.ROOT).endsWith("s")) {
                                plural = plural + "S";
                            }
                            game.insertAction(new DisplayText(game, "Crafted " + String.valueOf(SelectAmount.amount) + " " + this.crafts.get(index).name.toUpperCase(Locale.ROOT) + plural + "!", "fanfare1.ogg", true, true, (Action) new DisplayText.Clear(game, new SetField(this.prevMenu.prevMenu, "disabled", false, null))));
                        }
                    }
                } else if (InputProcessor.bJustPressed) {
                    game.insertAction(new PlayMusic("click1", (Action) null));
                    game.actionStack.remove(this);
                    this.prevMenu.disabled = false;
                    game.insertAction(this.prevMenu);
                }
            }
        }
    }
}
